package cpr.data;

import java.util.Comparator;

import cpr.Utils;

public     class SolveBestRulesComparator implements Comparator {
    int acc = 1;
    public SolveBestRulesComparator(boolean acc) {
        this.acc = (acc)?1:-1;
    }

    public int compare(Object o1, Object o2) {
        if (o1==o2) return 0;
        SolveBestRulesEntry a1 = (SolveBestRulesEntry)o1;
        SolveBestRulesEntry a2 = (SolveBestRulesEntry)o2;
        int d = acc*(a1.uncovered-a2.uncovered);
        if (d!=0) {
            return d;
        }
        d = acc*(a1.ares.length - a2.ares.length);
        if (d!=0) {
            return d;
        }
//        int s1 = 0;
//        int s2 = 0;
//        int scoresum1 = 0;
        for (int i = 0; i < a1.ares.length; i++) {
//			 s1+=Utils.printRuleAccordingToVectorDigital(a1.ares[i].rule, a1.ares[i].vector);
//			 s2+=Utils.printRuleAccordingToVectorDigital(a2.ares[i].rule, a2.ares[i].vector);
			 if (a1.ares[i].vector.score!=a2.ares[i].vector.score) {
				 return a1.ares[i].vector.score-a2.ares[i].vector.score;
			 }
			 d = Utils.compare(a1.ares[i].rule, a2.ares[i].rule, a1.ares[i].vector, a2.ares[i].vector);
        
			 if (d!=0) {
				 return d;
			 }
			 
        }
//        d = s1-s2;
//        if (d==0) {
//        	int t = 1;
//        } else {
//        	int t = 1;
//        }
        return 0;
    }
    
}
